<?php

class UserSettings extends Model{
	
	function UserSettings(){
		parent::Model();
	}
	
	function getStudentDetails($userid){
		$this->db->select("lastname, firstname, middlename, sex, address, occupation");
		$this->db->get_where("students", array("userid" => $userid));
	}
	
	function getTeacherDetails($userid){
		$this->db->select("lastname, firstname, middlename, sex, mobilenumber, photourl, academiccredentials");
		$this->db->get_where("teachers", array("userid" => $userid));
	}
	
	function saveStudentDetails($userid){
		$studentdetails = array(
		                         "lastname" => $this->input->post("lastname"),
		                         "firstname" => $this->input->post("firstname"),
		                         "middlename" => $this->input->post("middlename"),
		                         "sex" => $this->input->post("sex"),
		                         "address" => $this->input->post("address"),
		                         "occupation" => $this->input->post("occupation")
		                         );
		$this->db->where("userid", $userid);
		$this->db->update("students", $studentdetails);
	}
	
	function saveTeacherDetails($userid, $teacherdetails){
		$this->db->where("userid", $userid);
		$this->db->update("teachers", $teacherdetails);
	}
	
	function changePassword($userid, $usertype, $passdetails, $currpass){
		//I need multiple where conditions so multiple calls to where() din?
		$this->db->where("userid", $userid);
		$this->db->where("password", $currpass);
		if($usertype == 's'){
			$this->db->update("students", $passdetails);
		} else if($usertype == 't'){
			$this->db->update("teachers", $passdetails);
		} else{
			//uhhhh?
		}
	}
}
